package cn.shujuhai.qtadmin.platform.controller;

import org.jetbrains.annotations.NotNull;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.page.PageMethod;

import cn.hutool.core.text.CharSequenceUtil;
import cn.shujuhai.qtadmin.platform.domain.SysLogging;
import cn.shujuhai.qtadmin.platform.pluging.logging.BusinessType;
import cn.shujuhai.qtadmin.platform.pluging.logging.Logging;
import cn.shujuhai.qtadmin.platform.pluging.result.Result;


/**
 * 用户API
 *
 * @author dch798
 * @date 2021/08/21 22:13
 **/

@RestController
@RequestMapping("admin/log")
public class AdminLogController {
    /**
     *
     * @param page
     *            当前页
     * @return 用户列表
     */
    @PostMapping("logList")
    @Logging(title = "日志列表", describe = "日志列表", type = BusinessType.QUERY)
    public Result logList(Integer page, Integer limit, @NotNull SysLogging sysLog) {
        PageMethod.startPage(page == 0 ? 1 : page, limit == 0 ? 15 : limit);
        var queryWrapper = new QueryWrapper<SysLogging>().isNotNull("id");
        if (CharSequenceUtil.isNotBlank(sysLog.getTitle())) {
            queryWrapper.like("title", sysLog.getTitle());
        }
        if (CharSequenceUtil.isNotBlank(sysLog.getOperateName())) {
            queryWrapper.like("operate_name", sysLog.getOperateName());
        }
        var logList = sysLog.selectList(queryWrapper);
        return Result.success("获取成功", new PageInfo<>(logList));
    }
}
